package com.javaziliao.design.dprecated.state;

import com.javaziliao.design.utils.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DeprecatedCreateOrder extends DeprecatedAbstractOrderState {
    @Autowired
    private RedisCommonProcessor redisCommonProcessor;
    @Autowired
    private DeprecatedPayOrder deprecatedPayOrder;

    @Override
    public DeprecatedOrder createOrder(String orderId, String productId, DeprecatedOrderContext context) {
        // 创建订单成功后，将订单状态设置为待支付
        DeprecatedOrder order = DeprecatedOrder.builder()
                .orderId(orderId)
                .productId(productId)
                .state(ORDER_WAIT_PAY)
                .build();
        //新订单存入redis，15分钟后失效
        redisCommonProcessor.set(orderId,order,900);
        super.notifyObserver(orderId,ORDER_WAIT_PAY);
        return order;
    }
}
